package com.elong.businesstravel.modules.collect.adapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.elong.businesstravel.R;
import com.elong.businesstravel.entitys.HotelCollect;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;

public class HotelCollectAdapter extends BaseAdapter {

	private Context mContext;
	private List<HotelCollect> mHotelCollects;

	private boolean mDeleteFlag = false;

	public HotelCollectAdapter(Context context,
			List<HotelCollect> hotelCollects, boolean deleteFlag) {
		mContext = context;
		mHotelCollects = hotelCollects;
		mDeleteFlag = deleteFlag;
	}

	@Override
	public int getCount() {
		return mHotelCollects.size();
	}

	@Override
	public Object getItem(int arg0) {
		return mHotelCollects.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int position, View arg1, ViewGroup arg2) {

		if (null == arg1) {
			arg1 = LayoutInflater.from(mContext).inflate(
					R.layout.adapter_hotel_collect, null);
		}

		HotelCollect hotelCollect = mHotelCollects.get(position);

		TextView hotelNameTextView = (TextView) arg1
				.findViewById(R.id.hotelNameTextView);
		hotelNameTextView.setText(hotelCollect.hotelname);
		TextView hotelAddressTextView = (TextView) arg1
				.findViewById(R.id.hotelAddressTextView);
		hotelAddressTextView.setText(hotelCollect.address);

		ImageView imageView = (ImageView) arg1.findViewById(R.id.imageView);
		TextView deleteCollectTextView = (TextView) arg1
				.findViewById(R.id.deleteCollectTextView);
		ImageView drag_handle = (ImageView) arg1.findViewById(R.id.drag_handle);
		if (mDeleteFlag) {
			deleteCollectTextView.setVisibility(View.VISIBLE);
			drag_handle.setVisibility(View.VISIBLE);
			imageView.setVisibility(View.GONE);
		} else {
			deleteCollectTextView.setVisibility(View.GONE);
			imageView.setVisibility(View.VISIBLE);
			drag_handle.setVisibility(View.GONE);
		}

		return arg1;
	}

	public void setDeleteFlag(boolean deleteFlag) {
		mDeleteFlag = deleteFlag;
	}

	public boolean getDeleteFlag() {
		return mDeleteFlag;
	}

	public void remove(int position) {
		mHotelCollects.remove(position);
	}

	public void insert(HotelCollect hotelCollect, int position) {
		mHotelCollects.add(position, hotelCollect);
	}
}
